<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        图片
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

</head>

<style>
    /* .layui-form-label {
        width: 112px !important;
    } */
    .layui-tab {
        /* text-align: left !important;
        margin: 10px 0px; */
        overflow: auto !important;
    }
    .layui-upload-file {
        height: 0 !important;
    }

    .uploader-list {
        margin-left: -15px;
    }

    .uploader-list .info {
        position: relative;
        margin-top: -25px;
        background-color: black;
        color: white;
        filter: alpha(Opacity=80);
        -moz-opacity: 0.5;
        opacity: 0.5;
        width: 100px;
        height: 25px;
        text-align: center;
        display: none;
    }

    .uploader-list .handle {
        position: relative;
        background-color: black;
        color: white;
        filter: alpha(Opacity=80);
        -moz-opacity: 0.5;
        opacity: 0.5;
        width: 100px;
        text-align: right;
        height: 18px;
        margin-bottom: -18px;
        display: none;
    }

    .uploader-list .handle span {
        margin-right: 5px;
    }

    .uploader-list .handle span:hover {
        cursor: pointer;
    }

    .uploader-list .file-iteme {
        margin: 12px 0 0 15px;
        padding: 1px;
        float: left;
    }

</style>

<body>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="update" lay-filter="updateInfo">
        <div class="layui-tab-content">

            <div class="layui-upload"  style="margin-top: 8px;">
                <button type="button" class="layui-btn" id="test1">图片上传</button>
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    图片预览：
                    <div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list1">

                    </div>
                </blockquote>
            </div>

        </div>
        <div style="text-align: center" class="layui-form-item">
            <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                保存
            </button>
        </div>
    </form>
</div>

<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>

    // var id = getQueryVariable("id");

    layui.use(['laydate', 'table','form', 'layer','upload'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            okLoading.close($);

            laydate.render({
                elem: '#dueDate', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.rp.dueDate = value
                }
            });
            laydate.render({
                elem: '#joinTime',
                type: 'date',
            });


        });

    $(document).on("mouseenter mouseleave", ".file-iteme", function(event){
        if(event.type === "mouseenter"){
            //鼠标悬浮
            $(this).children(".info").fadeIn("fast");
            $(this).children(".handle").fadeIn("fast");
        }else if(event.type === "mouseleave") {
            //鼠标离开
            $(this).children(".info").hide();
            $(this).children(".handle").hide();
        }
    });
    // 删除图片
    $(document).on("click", ".file-iteme .handle", function(event){
        $(this).parent().remove();
    });

    const vm = new Vue({
        el: "#app",
        data: {
            nowLoginUser:{},
            buyerUser:[],
            jsonDataMaterialInPartsList:[],
            nowSelectPartId:'',
            nowSelectGysList:{},
            updatePartsGysIndex: ''
            // projectId:[],
            // rp: {
            //     id: null,
            //     billType: null,
            //     billAmount: null,
            //     dueDate: null,
            //     personInChargeOfTheBill: null,
            //     relatedCustomers: null,
            //     associatedItems: null,
            //     relatedContract: null,
            //     payer: null,
            //     remark: null,
            //     type: null,
            //     skUnit: null,
            //     yfDate: null,
            // }
        },
        created() {

        },
        computed: {},
        methods: {

        },
        mounted() {
            var that = this;

                layui.use(['table', 'form', 'upload','layer'], function() {
                    var form = layui.form;
                    var upload = layui.upload;

                    var jsonImgUrlData = JSON.parse(sessionStorage.getItem('imgUrlData'));

                    var imgArr = jsonPartData.siteImg.split("|");
                    for(var i = 0; i < siteImgArr.length; i++) {
                        $('#uploader-list1').append(
                            '<div id="" class="file-iteme">' +
                            '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                            '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+siteImgArr[i]+'>' +
                            // '<div class="info">' + res.name + '</div>' +
                            '</div>'
                        );
                    }

                    var partsmsgImgArr = jsonPartData.partsmsgImg.split("|");
                    for(var j = 0; j < siteImgArr.length; j++) {
                        $('#uploader-list2').append(
                            '<div id="" class="file-iteme">' +
                            '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                            '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+siteImgArr[j]+'>' +
                            // '<div class="info">' + res.name + '</div>' +
                            '</div>'
                        );
                    }
                    var payEvidenceImgArr = jsonPartData.payEvidenceImg.split("|");
                    for(var k = 0; k < siteImgArr.length; k++) {
                        $('#uploader-list3').append(
                            '<div id="" class="file-iteme">' +
                            '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                            '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+siteImgArr[k]+'>' +
                            // '<div class="info">' + res.name + '</div>' +
                            '</div>'
                        );
                    }
                    //表单赋值
                    form.val("updateInfo", { //updateInfo 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                        "site": jsonPartData.site,

                    });
                    form.render();
                    //多图片上传1
                    upload.render({
                        elem: '#test1'
                        ,url: baseHead+'other/fileUpload1' //改成您自己的上传接口
                        ,multiple: true
                        ,before: function(obj){
                            layer.msg('图片上传中...', {
                                icon: 16,
                                shade: 0.01,
                                time: 0
                            })
                        }
                        ,done: function(res){
                            layer.close(layer.msg());//关闭上传提示窗口
                            if(res.code == 0){
                                // picUrl = res.data;
                                //上传完毕
                                $('#uploader-list1').append(
                                    '<div id="" class="file-iteme">' +
                                    '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                                    '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+res.data+'>' +
                                    // '<div class="info">' + res.name + '</div>' +
                                    '</div>'
                                );
                            }
                            else {
                                layer.alert("上传失败，请重新上传！");
                            }

                        }
                    });
                    //多图片上传2
                    upload.render({
                        elem: '#test2'
                        ,url: baseHead+'other/fileUpload1' //改成您自己的上传接口
                        ,multiple: true
                        ,before: function(obj){
                            layer.msg('图片上传中...', {
                                icon: 16,
                                shade: 0.01,
                                time: 0
                            })
                        }
                        ,done: function(res){
                            layer.close(layer.msg());//关闭上传提示窗口
                            if(res.code == 0){
                                // picUrl = res.data;
                                //上传完毕
                                $('#uploader-list2').append(
                                    '<div id="" class="file-iteme">' +
                                    '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                                    '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+res.data+'>' +
                                    // '<div class="info">' + res.name + '</div>' +
                                    '</div>'
                                );
                            }
                            else {
                                layer.alert("上传失败，请重新上传！");
                            }

                        }
                    });
                    //多图片上传3
                    upload.render({
                        elem: '#test3'
                        ,url: baseHead+'other/fileUpload1' //改成您自己的上传接口
                        ,multiple: true
                        ,before: function(obj){
                            layer.msg('图片上传中...', {
                                icon: 16,
                                shade: 0.01,
                                time: 0
                            })
                        }
                        ,done: function(res){
                            layer.close(layer.msg());//关闭上传提示窗口
                            if(res.code == 0){
                                // picUrl = res.data;
                                //上传完毕
                                $('#uploader-list3').append(
                                    '<div id="" class="file-iteme">' +
                                    '<div class="handle"><span class="glyphicon glyphicon-trash" ></span></div>' +
                                    '<img class="upImgUrl" style="width: 100px;height: 100px;" src='+ baseHead +'/other/viewUploadFile?id='+res.data+'>' +
                                    // '<div class="info">' + res.name + '</div>' +
                                    '</div>'
                                );
                            }
                            else {
                                layer.alert("上传失败，请重新上传！");
                            }

                        }
                    });

                    form.on('submit(sub)', function (data) {
                        // if(picUrl == null){
                        //     picUrl = oldUrl;
                        // }


                        var siteImgUrlArr = [];
                        $("#uploader-list1 img").each(function () {
                            siteImgUrlArr.push($(this).attr("src").split('=')[1]);
                            // imgsTotalUrl += $(this).attr("src").split('=')[1] +  "|" ;
                        });
                        var partsmsgImgUrlArr = [];
                        $("#uploader-list2 img").each(function () {
                            partsmsgImgUrlArr.push($(this).attr("src").split('=')[1]);
                            // imgsTotalUrl += $(this).attr("src").split('=')[1] +  "|" ;
                        });
                        var payEvidenceImgUrlArr = [];
                        $("#uploader-list3 img").each(function () {
                            payEvidenceImgUrlArr.push($(this).attr("src").split('=')[1]);
                            // imgsTotalUrl += $(this).attr("src").split('=')[1] +  "|" ;
                        });
                        var val = {};
                        // val.userId = $userId;
                        val.id = jsonPartData.partsMsgId;
                        val.site = data.field.site;
                        val.siteImg = siteImgUrlArr.join("|");
                        val.partsmsgImg = partsmsgImgUrlArr.join("|");
                        val.payEvidenceImg = payEvidenceImgUrlArr.join("|");
                        let request = {
                            url: 'kf/partsJoinWarehouse/updateJoinparts',
                            data: val,
                            method: "post",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.alert("操作成功", {
                                        icon: 6
                                    },
                                    function () {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                        parent.location.reload();

                                    });
                            } else {
                                layer.alert(data.msg, {
                                    icon: 5
                                })
                            }
                        });
                        return false;
                    });

                });
            // })
        }


    });

    // setTimeout(() => {
    //     //修改状态
    //     let form = layui.form;
    //     //账单类型
    //     let request = {
    //         url: 'dictionary/findDataDictionaryValue',
    //         data: {
    //             userId: $userId,
    //             label: 'BILL_TYPE'
    //         },
    //         method: "POST",
    //     };
    //     sendRequest(request, (res) => {
    //         let x = res.data;
    //         $.each(x, function (index, item) {
    //             let opt = $("<option value=" + item + ">" + item + "</option>");
    //             $("select[name=billType]").append(opt);
    //
    //         });
    //
    //         $("select[name=billType]").val(vm.rp.billType);
    //
    //         form.render('select');
    //     });
    // }, 300)

</script>

</body>

</html>
